﻿Public Class FormReceive
    Public usr As String
    Dim dtCk As New DataTable
    Dim objCA As New clsLXCK
    Dim objProdInfo As New clsProdInfo
    Dim prod_ids As String
    Private Sub FormReceive_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        initDt()
    End Sub

    Public Sub initDt()
        dtCk.Columns.Add("sys_id")
        dtCk.Columns.Add("wh_no")
        dtCk.Columns.Add("prod_id")
        dtCk.Columns.Add("b_pgd_mes_sys_id")
        dtCk.Columns.Add("out_time")
        dtCk.Columns.Add("out_ope")
        dtCk.Columns.Add("type_value")
    End Sub


    Private Sub txtProdId_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtProdId.KeyPress
        If String.IsNullOrEmpty(txtProdId.Text.Trim()) = False Then
            If e.KeyChar = vbCr Then
                Dim dt As DataTable = objCA.getListByProdId(txtProdId.Text.Trim(), "1")
                If dt.Rows.Count >= 1 Then
                    Dim dr As DataRow() = dtCk.Select("sys_id='" & dt.Rows(0)("sys_id") & "'")
                    If dr.Length = 0 Then
                        dtCk.Rows.Add(dt.Rows(0)("sys_id"), dt.Rows(0)("location"), dt.Rows(0)("prod_id"),
                                    dt.Rows(0)("b_pgd_mes_sys_id"), dt.Rows(0)("out_date"), dt.Rows(0)("out_ope"), dt.Rows(0)("type_value"))
                        prod_ids &= "'" & dt.Rows(0)("prod_id") & "',"
                        dgv.AutoGenerateColumns = False
                        dgv.DataSource = dtCk
                        txtProdId.Text = String.Empty
                        txtProdId.Focus()
                    Else
                        MsgBox("该标签号已在表格中存在！", vbYes, "提示")
                    End If
                Else
                    If dt.Rows.Count = 0 Then
                        MsgBox("未查询到此生产编号出库信息", vbYes, "提示")
                    End If
                End If
            End If
        End If
    End Sub

    Private Sub btnReceive_Click(sender As Object, e As EventArgs) Handles btnReceive.Click
        If String.IsNullOrEmpty(usr) = False Then
            If dtCk.Rows.Count > 0 Then
                If MsgBox("确认接收吗？", vbYesNo, "提示") = vbYes Then
                    If prod_ids.Length > 0 Then
                        prod_ids = prod_ids.Substring(0, prod_ids.Length - 1)
                    End If
                    If objProdInfo.updateProdInfo(prod_ids, usr) = -2 Then
                        MsgBox("接收失败", vbYes, "提示")
                    Else
                        CType(Owner, FormMain).setDgvData()
                        MsgBox("接收成功", vbYes, "提示")
                        dtCk.Rows.Clear()
                        txtProdId.Focus()
                    End If
                End If
            Else
                MsgBox("请扫描或输入标签号，进行接收", vbYes, "提示")
            End If
        Else
            MsgBox("请勾选用户", MsgBoxStyle.Information, "喷漆")
        End If
    End Sub

    Private Sub btnReceiveAndWorkReport_Click(sender As Object, e As EventArgs) Handles btnReceiveAndWorkReport.Click
        If String.IsNullOrEmpty(usr) = False Then
            If dtCk.Rows.Count > 0 Then
                If MsgBox("确认接收并生产报工吗？", vbYesNo, "提示") = vbYes Then
                    If prod_ids.Length > 0 Then
                        prod_ids = prod_ids.Substring(0, prod_ids.Length - 1)
                    End If
                    If objProdInfo.updateProdInfoWR(prod_ids, usr) = -2 Then
                        MsgBox("接收并生产报工失败", vbYes, "提示")
                    Else
                        CType(Owner, FormMain).setDgvData()
                        MsgBox("接收并生产报工成功", vbYes, "提示")
                        dtCk.Rows.Clear()
                        txtProdId.Focus()
                    End If
                End If
            Else
                MsgBox("请扫描或输入标签号，进行接收", vbYes, "提示")
            End If
        Else
            MsgBox("请勾选用户", MsgBoxStyle.Information, "喷漆")
        End If
    End Sub

    Private Sub btnRemove_Click(sender As Object, e As EventArgs) Handles btnRemove.Click
        If dgv.SelectedRows.Count > 0 Then
            dtCk.Rows.RemoveAt(dgv.CurrentRow.Index)
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dtCk
        End If
    End Sub

End Class